package com.jinyijia.api.rest.v1;

import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

/**
 * @author yangrd
 * @version 1.0.0
 * @date 2018/9/20
 **/
@RestController
@RequestMapping("/version")
public class AndroidVersionController {

    @Data
    @Component
    @ConfigurationProperties(prefix = "android-version")
    static class AndroidVersion {
        private Integer versionCode;
        private String version;
        private String downloadUrl;
    }

    private AndroidVersion androidVersion;

    @GetMapping
    public AndroidVersion getVersion(){
        return getAndroidVersion();
    }

    @PutMapping
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public void change(@RequestBody AndroidVersion androidVersion){
        this.setAndroidVersion(androidVersion);
    }

    private AndroidVersion getAndroidVersion() {
        return androidVersion;
    }

    @Autowired
    public void setAndroidVersion(AndroidVersion androidVersion) {
        this.androidVersion = androidVersion;
    }
}
